<?php
include '../../config/database.php';
$issett = true;
$linkssql = $dbprefix.'links';
$lid=$_GET['lid'];
if($_POST['code']!=1 || !isset($_POST['code']))
{
	if($lid!='' && $lid > 0)
	{
		$con = mysqli_connect($dbhost,$dbuser,$dbpasswd,$dbname);
		$sql = "SELECT * FROM ".$linkssql.' WHERE `id` = '.$_GET['lid'];

		$result = mysqli_query($con, $sql);

		if (mysqli_num_rows($result) > 0) 
		{
			while($row = mysqli_fetch_assoc($result)) {
				$name = $row['name'];
				$long_url = $row['long_url'];
				$short_url_code = $row['short_url_code'];
			}
		} else {$issett=false;}
	}
	else $issett=false;
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no">
		<title>
		YunBan | 添加封禁
		</title>
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/mdui@0.4.2/dist/css/mdui.min.css">
		<script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js">
		</script>
		<script src="https://cdn.jsdelivr.net/npm/mdui@0.4.2/dist/js/mdui.min.js">
		</script>
	</head>
	<body class="mdui-drawer-body-left mdui-appbar-with-toolbar mdui-theme-primary-indigo mdui-theme-accent-blue">
		<div class="mdui-appbar mdui-appbar-fixed">
			<div class="mdui-toolbar mdui-color-theme">
				<button class="mdui-btn mdui-btn-icon" mdui-drawer="{target:'#sidebar'}">
					<i class="mdui-icon material-icons">
						&#xe5d2;
					</i>
				</button>
				<a href="./" class="mdui-typo-headline">
                YunBan | 添加封禁
				</a>
				<div class="mdui-toolbar-spacer">
				</div>
			</div>
		</div>
		
		<div class="mdui-drawer" id="sidebar">
			<div class="mdui-list" mdui-collapse="{accordion:true}">
				<a href="../" class="mdui-list-item mdui-ripple">
					<i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-blue">
						&#xe88a;
					</i>
					<div class="mdui-list-item-content">
						短链管理
					</div>
				</a>
				<a href="./" class="mdui-list-item mdui-list-item-active mdui-ripple">
					<i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-green">
                        &#xe145;
					</i>
					<div class="mdui-list-item-content">
                    玩家名称
					</div>
				</a>
				<a href="../delete" class="mdui-list-item mdui-ripple">
					<i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-brown">
						&#xe872;
					</i>
					<div class="mdui-list-item-content">
						删除短链
					</div>
				</a>
				<a href="../logout" class="mdui-list-item mdui-ripple">
					<i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-orange">
						&#xe0b8;
					</i>
					<div class="mdui-list-item-content">
						登出
					</div>
				</a>

				<a href="//github.com/imjinglan/TinyLink" class="mdui-list-item mdui-ripple" target = '_blank'>
					<div class="mdui-list-item-content">
						<strong>POWERED BY TINYLINK</strong>
					</div>
				</a>

			</div>
		</div>
		<div class="mdui-container mdui-typo mdui-text-color-theme">
			<h1 class="">
            添加封禁
			</h1>
			
            <form class="content database" action="./" method="post">
    			<div class="mdui-textfield mdui-textfield-floating-label" style ="display:none">
                  <label class="mdui-textfield-label"></label>
                  <input class="mdui-textfield-input" value="<?php echo $_GET['lid']?>" name="lid"/>
                </div>

				<div class="mdui-textfield mdui-textfield-floating-label" style ="display:none">
                  <label class="mdui-textfield-label"></label>
                  <input class="mdui-textfield-input" value="1" name="code"/>
                </div>

    			<div class="mdui-textfield mdui-textfield-floating-label">
                  <label class="mdui-textfield-label">用户名 | UUID (请在下方启用)</label>
                  <input class="mdui-textfield-input" value="<?php echo $name?>" name="player"/>
                </div>
    			
				<div class="mdui-textfield mdui-textfield-floating-label">
                  <label class="mdui-textfield-label">封禁原因</label>
                  <input class="mdui-textfield-input" value="<?php echo $long_url?>" name="long_url"/>
                </div>
                <label class="mdui-textfield-label">封禁时长</label>
				<select class="mdui-select mdui-text-color-black" mdui-select>
					<option value="1">5分钟</option>
					<option value="2">15分钟</option>
					<option value="3">30分钟</option>
					<option value="4">1小时</option>
					<option value="5">3小时</option>
					<option value="6">6小时</option>
					<option value="7">12小时</option>
					<option value="8">24小时</option>
					<option value="9">72小时</option>
					<option value="10">1个月</option>
					<option value="11">3个月</option>
					<option value="12">6个月</option>
					<option value="13">1年</option>
					<option value="14">2年</option>
					<option value="15">3年</option>
				</select>
                <div>
                <label class="mdui-textfield-label">UUID(默认情况下将会自动获取玩家UUID)</label>
                <label class="mdui-switch">
                    <input type="checkbox"/>
                    <i class="mdui-switch-icon"></i>
                </label>
</div>
                <div class="mdui-textfield mdui-textfield-floating-label" style="display:none">
                  <label class="mdui-textfield-label">DATE</label>
                  <input class="mdui-textfield-input" value="<?php echo date('Ymd');?>" name="date"/>
                </div>

                <div class="mdui-textfield mdui-textfield-floating-label">
    			<button class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-theme-accent">回答</button></div>
			</form>	    
		</div>
		<script>
			$(function() {});
		</script>
		<style>
			.dictumanchor{position:relative;top:-56px}@media (min-width:600px){.dictumanchor{top:-64px!important}}@media
			(orientation:landscape) and (max-width:959px){.dictumanchor{top:-48px!important}}
		</style>
	</body>

</html>
<?php }

if($_POST['code']==1)
{
	function getuuid($player)
	{
		ini_set('user_agent', 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 4 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19');
		$opts = [
			'http' => [
					'method' => 'GET',
					'header' => [
							'User-Agent: PHP'
					]
			]
		];
		$context = stream_context_create($opts);
		$apiurl = 'https://api.mojang.com/users/profiles/minecraft/'.$player;
		$json = file_get_contents($apiurl,true, $context);
        $decode = json_decode($json);
		return $decode->id;
	}


	$sql = "INSERT INTO `" .$dbprefix. "reason`(`uuid`, `reason`, `start_time`,`end_time`) VALUES ('" .getuuid(''). "', '" .nohttp($_POST['long_url']). "', '" .$_POST['short_url_code']. "');";
	//echo $sql;
	$con = mysqli_connect($dbhost,$dbuser,$dbpasswd,$dbname);
	$result = mysqli_query($con, $sql);
	echo '添加成功';
	?>
	
<meta http-equiv="refresh" content="2;url=./?lid=<?php echo $_POST['lid']?>">
	<?php
}

?>